<?php

namespace app\api\model;

use think\Model;
use traits\model\SoftDelete;

class Courses extends Model
{
    use SoftDelete;

    protected $deleteTime = 'deletetime';

    public static function getCourse($class_id, $date)
    {
        return self::where('class_id', $class_id)->where('date', $date)->orderRaw('cast(`time` as time) asc')->select();
    }

    public function times()
    {
        return $this->hasOne(Times::class, 'id', 'time_id');
    }

    public function timetables()
    {
        return $this->hasOne(TimeTables::class, 'id', 'timetable_id');
    }

    public static function getByMonth($date, $class_id)
    {
        $dates = self::where('class_id', $class_id)->where('date', 'like', "$date%")->column('date');
        return array_unique($dates);
    }
}
